package tedu.api.binary;

public class Demo10 {
    public static void main(String[] args) {
        int n = 0x6a7b9cef;
        System.out.println(Integer.toBinaryString(n));


        byte[] bytes = toBytes(n);
        int m = toInt(bytes);
        System.out.println(Integer.toBinaryString(m));


    }
    public static byte[] toBytes(int n){
        int b1 = (n>>>24) & 0xff;
        int b2 = (n>>>16) & 0xff;
        int b3 = (n>>>8) & 0xff;
        int b4 = (n>>>0) & 0xff;
        System.out.println("toBytesb1--b4");
        System.out.println(b1);
        System.out.println(b2);
        System.out.println(b3);
        System.out.println(b4);
        return new byte[]{(byte)b1, (byte)b2, (byte)b3, (byte)b4};
    }

    public static int toInt(byte[] bytes){
        System.out.println("toInt数组0-3");
        System.out.println(bytes[0]);
        System.out.println(bytes[1]);
        System.out.println(bytes[2]);
        System.out.println(bytes[3]);
        System.out.println(Integer.toBinaryString(bytes[3]));
        int b1 = bytes[0] & 0xff;
        int b2 = bytes[1] & 0xff;
        int b3 = bytes[2] & 0xff;
        int b4 = bytes[3] & 0xff;
        System.out.println("toIntb1--b4");
        System.out.println(b1);
        System.out.println(b2);
        System.out.println(b3);
        System.out.println(b4);

        return (b1<<24) | (b2<<16) | (b3<<8) | (b4<<0);
    }
}
